﻿using AutoMapper;
using B.S.Traceable.Domain.Entitiy;
using B.S.Traceable.ErrorCode;
using B.S.Traceable.Infrasturcture.Interfaces;
using B.S.Traceable.Read.Api.Application.Command.Shop;
using MediatR;

namespace B.S.Traceable.Read.Api.Application.CommandHandler.Shop
{
    public class GetShopHandler : IRequestHandler<GetShopCommand, ApiResult<List<ShopModel>>>
    {

        private readonly IBaseRepository<ShopModel> shopRepo;

        public GetShopHandler(IBaseRepository<ShopModel> shopRepo)
        {
            this.shopRepo = shopRepo;
        }

        public Task<ApiResult<List<ShopModel>>> Handle(GetShopCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ShopModel>> result = new ApiResult<List<ShopModel>>();
            result.Code = ApiEnums.Success;
            result.Msg = "查询成功";
            var model = shopRepo.GetAll();

            result.Data = model.ToList();
            return Task.FromResult(result);
        }
    }
}
